package cn.dmp.utils

import org.apache.spark.sql.Row

import scala.collection.mutable.ListBuffer

/**
  * 两个功能：
  *     1.封装用户是否存在的字符串判断
  *     2.得到所有用户的id
 */
object TagsUtils {

  val hasSomeUserIdCondition =
    """
      |Imei != "" or Imeimd5 != "" or Imeisha1 != "" or
      |Idfa != "" or Idfamd5 != "" or Idfasha1 != "" or
      |Imac != "" or Macmd5 != "" or Macsha1 != "" or
      |Androidid != "" or Androididmd5 != "" or Androididsha1 != "" or
      |Openudid != "" or Openudidmd5 != "" or Openudidsha1 != ""
    """.stripMargin

  def getAllUserId(row: Row): ListBuffer[String] ={

    val userIds = new collection.mutable.ListBuffer[String]()

    if(row.getAs[String]("Imei").nonEmpty) userIds.append("IM"+v.getAs[String]("Imei").toUpperCase())
    if(row.getAs[String]("Idfa").nonEmpty) userIds.append("DF"+v.getAs[String]("Idfa").toUpperCase())
    if(row.getAs[String]("Imac").nonEmpty) userIds.append("MC"+v.getAs[String]("Imac").toUpperCase())
    if(row.getAs[String]("Androidid").nonEmpty) userIds.append("AD"+v.getAs[String]("Androidid").toUpperCase())
    if(row.getAs[String]("Openudid").nonEmpty) userIds.append("OU"+v.getAs[String]("Openudid").toUpperCase())

    if(row.getAs[String]("Imeimd5").nonEmpty) userIds.append("IM"+v.getAs[String]("Imeimd5").toUpperCase())
    if(row.getAs[String]("Idfamd5").nonEmpty) userIds.append("DF"+v.getAs[String]("Idfamd5").toUpperCase())
    if(row.getAs[String]("Imacmd5").nonEmpty) userIds.append("MC"+v.getAs[String]("Imacmd5").toUpperCase())
    if(row.getAs[String]("Androididmd5").nonEmpty) userIds.append("AD"+v.getAs[String]("Androididmd5").toUpperCase())
    if(row.getAs[String]("Openudidmd5").nonEmpty) userIds.append("OU"+v.getAs[String]("Openudidmd5").toUpperCase())

    if(row.getAs[String]("Imeisha1").nonEmpty) userIds.append("IM"+v.getAs[String]("Imeisha1").toUpperCase())
    if(row.getAs[String]("Idfasha1").nonEmpty) userIds.append("DF"+v.getAs[String]("Idfasha1").toUpperCase())
    if(row.getAs[String]("Imacsha1").nonEmpty) userIds.append("MC"+v.getAs[String]("Imacsha1").toUpperCase())
    if(row.getAs[String]("Androididsha1").nonEmpty) userIds.append("AD"+v.getAs[String]("Androididsha1").toUpperCase())
    if(row.getAs[String]("Openudidsha1").nonEmpty) userIds.append("OU"+v.getAs[String]("Openudidsha1").toUpperCase())

    userIds

  }

}
